define(['jquery', 'bootstrap', 'backend', 'table', 'form'],function($, undefined, Backend, Table, Form){
    var Controller = {
        index:function(){
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'subject/subject/index',
                    add_url: 'subject/subject/add',
                    edit_url: 'subject/subject/edit',
                    del_url: 'subject/subject/del',
                    multi_url: 'subject/subject/multi',
                    info_url: 'subject/info/index',
                    chapter_url: 'subject/chapter/index',
                    table: 'subject', // 表名
                }
            });

            // 获取到table标签的id
            var table = $("#table")

            // 初始化表格
            table.bootstrapTable({
                // 当访问列表发起ajax请求数据
                url:$.fn.bootstrapTable.defaults.extend.index_url,
                // 主键
                pk:'id',
                // 设置默认排序
                sortName:'createtime',
                sortOrder:'desc',
                columns:[
                    [
                        {checkbox: true},
                        {field:'id',title:__('Id'),sortable: true, operate: false},
                        {field:'title',title:__('Stitle'), operate: 'LIKE'},
                        {field:'category.name',title:__('Cname')},
                        {field:'teacher.name',title:__('Tname'), operate: 'LIKE'},
                        {field: 'thumbs_text', title: __('Image'), formatter: Table.api.formatter.image, operate: false},
                        {field:'price',title:__('Sprice'),sortable: true, operate: false},
                        {field:'likes_text',title:__('Slikes'), operate: false},
                        {field: 'createtime', title: __('Createtime'), operate: 'RANGE', addclass: 'datetimerange', formatter: Table.api.formatter.datetime},
                        {
                            field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: 'info',
                                    title: function(item){
                                        return  __(item.title + '课程详情');
                                      },
                                    classname: 'btn btn-xs btn-success btn-dialog',
                                    icon: 'fa fa-ellipsis-h',
                                    url: $.fn.bootstrapTable.defaults.extend.info_url,
                                    extend: 'data-toggle=\'tooltip\' data-area= \'["80%", "100%"]\'',
                                },
                                {
                                    name: 'chapter',
                                    title: function(item){
                                        return  __(item.title + '章节详情');
                                    },
                                    classname: 'btn btn-xs btn-success btn-dialog',
                                    icon: 'fa fa-list',
                                    url: $.fn.bootstrapTable.defaults.extend.chapter_url,
                                    extend: 'data-toggle=\'tooltip\' data-area= \'["80%", "100%"]\'',
                                }
                            ]
                        }
                    ]
                ]
            })

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        // 添加
        add:function()
        {
            // 为表单绑定事件
            Controller.api.bindevent();
        },
        edit:function()
        {
            Controller.api.bindevent();
        },
        del:function()
        {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    }


    return Controller
})